package com.bw.tig.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.tig.entity.DUser;
import com.bw.tig.service.IDUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xingjinning
 * @since 2020-06-10
 */
@RestController
@RequestMapping("/user")
public class DUserController {

    @Autowired
    private IDUserService userService;

    @PostMapping("/login")
    public Map<String,Object> login(@RequestBody DUser duser){
        Map<String, Object> map = new HashMap<>();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("username",duser.getUsername());
        queryWrapper.eq("pwd",duser.getPwd());
        DUser user = userService.getOne(queryWrapper);
        if(null!=user){
            map.put("user",user);
            map.put("role",user.getRole());
            return map;
        }else{
            return null;
        }
    }
}
